<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>终端信息管理</title>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<link href="../../pages/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="../../pages/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
<link rel="stylesheet" href="../../pages/bootstrap/animate.min.css">
<link rel="stylesheet" href="../../pages/common/styles/common.css">
<script src="../../pages/jquery/jquery-1.12.4.min.js"></script>
<script src="../../pages/bootstrap/js/bootstrap.min.js"></script>
<script src="../../pages/common/js/bootstrap-grid.js"></script>
<script src="../../pages/common/js/common.js"></script>
</head>
<body class="animated fadeInRight">

<!-- 用户管理界面显示 -->
	<div class="tabBar">
		<div class="tab">
			<img src="../../pages/images/adminImages/tab_admin_manager.png">
			管理员信息管理
		</div>
		<div class="tab">
			<img src="../../pages/images/adminImages/tab_admin_manager.png">
			管理员信息新建
		</div>
		<div class="tab">
			<img src="../../pages/images/adminImages/tab_admin_update.png">
			管理员信息修改
		</div>
	</div>
	<div class="tab-main tab-active">
		<div>
			<a id="btnAdd" class="a-btn-blue"><span class="glyphicon glyphicon-plus font-size-12px"></span>&nbsp;新增</a>
			<a id="btnEdit" class="a-btn-green"><span class="glyphicon glyphicon-pencil font-size-12px"></span>&nbsp;修改</a>
			<a id="btnDel" class="a-btn-red"><span class="glyphicon glyphicon-remove font-size-12px"></span>&nbsp;删除</a>
			
			<a id="advancedSearchbtnAdmin" class="a-btn-gray2 inline pull-right" style="color: #03a9f4;text-decoration: none">
			<span id="advancedSearchAdminText">高级搜索</span>&nbsp;
			<span id="advancedSearchAdminSpan" class="glyphicon glyphicon-chevron-down" title="高级搜索"></span></a>
			
			<div class="pull-right input-group" role="group" style="width: 30%;margin-right: 10px">
				<input id="searchFieldAdmin" type="text" class="form-control" placeholder="输入管理员账号或名称" aria-describedby="basic-addon2" >
				<span class="input-group-addon search-cusor" id="btnSearchAdmin"><img alt="" src="../../pages/images/search.png"></span>
			</div>
		</div>
		
		<div id="advancedSearchAdmin" style="margin-top:10px; display: none;">
			<table style="float: right;margin-right: 100px;margin-top: 10px;">
				<tr>
					<td style="padding-right: 10px;">
					</td>
					<td style="width: 300px;">
						<input id="searchType" type="text" class="form-control" style="width: 250px;" placeholder="请输入类型">
					</td>
					<td style="padding-right: 10px;">
					</td>
					<td style="width: 300px;">
						<input id="searchStatus" type="text" class="form-control" style="width: 250px;" placeholder="请输入状态">
					</td>
				</tr>
			</table>
		</div>
		
		
		
		
		<div>
			<table id="adminManagerTable" class="table table-striped table-hover">
			  <thead>
			    <tr>
			      <th field="account">管理员账号</th>
			      <th field="name">管理员名称</th>
			      <th field="type">类别</th>
			      <th field="status">状态</th>
			    </tr>
			  </thead>
			  <tbody>
			  </tbody>
			</table>
			<div style="margin-bottom: 10px;">
			  <ul id="adminManagerTable_page" class="pagination">
			  	<!-- 
			    <li><a>上一页</a></li>
			    <li class="active"><a>1</a></li>
			    <li><a>2</a></li>
			    <li><a>3</a></li>
			    <li><a>4</a></li>
			    <li><a>5</a></li>
			    <li><a>6</a></li>
			    <li><a>7</a></li>
			    <li><a>8</a></li>
			    <li><a>9</a></li>
			    <li><a>10</a></li>
			    <li><a>下一页</a></li>-->
			  </ul>
			   
			  <div class="pull-right" style="margin-top: 25px;padding-right: px">
			  	<!-- 显示分页参数  -->
			  </div>
			 </div>
		</div>
	</div>
	
	<!-- 专家信息新增页 -->
	<div class="tab-main">
		<table class="table-form" style="width: 100%;">
			<tr>
				<th width="10%"><font color="red">*</font>管理员账号</td>
				<td width="40%">
					<input id="account" type="text" class="form-control inline"  aria-describedby="basic-addon1">
				</td>
				<th width="10%"><font color="red">*</font>管理员密码</th>
				<td width="40%">
					<input id="password" type="text" class="form-control"  aria-describedby="basic-addon1">
				</td>
			</tr>
			<tr>
				<th width="10%"><font color="red">*</font>管理员名称</th>
				<td width="40%">
					<input id="name" type="text" class="form-control"  aria-describedby="basic-addon1">
				</td>
				<th width="10%">类型</th>
				<td width="40%">
					<input id="type" type="text" class="form-control" aria-describedby="basic-addon1">
				</td>
			</tr>
			<tr>
				<th width="10%">状态</th>
				<td width="40%">
					<input id="status" type="text" class="form-control" aria-describedby="basic-addon1">
				</td>
			</tr>
			
			<tr>
				<td colspan="4" style="text-align: center;">
					<a id="save" class="a-btn-submit" onclick="addAdminManagerInfo()" >提 &nbsp;&nbsp;交</a>
					<a id="reset" class="a-btn-cancel" onclick="resetAdminNamagerInfo()" style="margin-left: 50px;">重 &nbsp;&nbsp;置</a>	
				</td>
			</tr>
		</table>
	</div>
	<!-- 专家信息修改页 -->
	<div class="tab-main">
		<table class="table-form" style="width: 100%;">
			<tr style="display: none;">
				<th width="10%">id</td>
				<td width="40%">
					<input id="u_id" type="text" class="form-control"  aria-describedby="basic-addon1">
				</td>
			</tr>
			<tr>
				<th width="10%"><font color="red">*</font>管理员账号</td>
				<td width="40%">
					<input id="u_account" type="text" class="form-control inline"  aria-describedby="basic-addon1"  readonly="true">
				</td>
				<th width="10%"><font color="red">*</font>管理员密码</th>
				<td width="40%">
					<input id="u_password" type="text" class="form-control"  aria-describedby="basic-addon1">
				</td>
			</tr>
			<tr>
				<th width="10%"><font color="red">*</font>管理员名称</th>
				<td width="40%">
					<input id="u_name" type="text" class="form-control"  aria-describedby="basic-addon1">
				</td>
				<th width="10%">类型</th>
				<td width="40%">
					<input id="u_type" type="text" class="form-control" aria-describedby="basic-addon1">
				</td>
			</tr>
			<tr>
				<th width="10%">状态</th>
				<td width="40%">
					<input id="u_status" type="text" class="form-control" aria-describedby="basic-addon1">
				</td>
			</tr>
			<tr style="">
				<td colspan="4" style="text-align: center;">
					<a id="update" class="a-btn-submit" onclick="updateAdminNamagerManagerInfo()">提 &nbsp;&nbsp;交</a>
				</td>
			</tr>
		</table>
	</div>
	<div class="tab-main">
		
		<form id="uploadForm" action="${ctx}/user/exportUsers" method="post" enctype="multipart/form-data">
			<table class="table-form" style="width: 100%;">
				<tr>
					<td>
					<tr>
						<th width="20%">用户批量导入（*.xlsx\*.xls）：</th>
						<td width="30%">
						<!-- <label class="control-label"></label> -->	
							<input id="file" type="file"  class="file-loading" name="file" style="width:220px;">
							<a class="a-btn-importfile" onclick="exportUsers()">导入文件</a>
							&nbsp;&nbsp;
							<a class="a-btn-downloadfile" onclick="downloadTemp()">下载模板</a>
						</td>
					</tr>
						
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
<script type="text/javascript">

$(document).ready(function() {
	$("#adminManagerTable").initGrid(0);
	$(".tab").eq(0).click();
    query();
});

function query(){
	var pageSize = parseInt(window["adminManagerTable_page"].pageSize);
	var pageNum = parseInt(window["adminManagerTable_page"].pageNum);
	$.ajax({
        type: "post",
        dataType: "json",
        url: '${ctx}/sysUser/getUserList',
        data:{
        	pageNum:pageNum,
        	pageSize:pageSize,
        	type:$("#searchType").val(),
        	status:$("#searchStatus").val(),
        	searchField:$("#searchFieldAdmin").val()
        },
        success: function (data) {
        	$("#adminManagerTable").loadGrid(data);
        },
		error:function(){
		}
    });
}

/**
 * 点击新增，跳转到新增界面
 * 执行提交和重置事件
 */
$("#btnAdd").on("click",function(){
	$(".tab").eq(1).click();
});
function addAdminManagerInfo(){
		var account = document.getElementById("account"); 
		var password = document.getElementById("password"); 
		var name = document.getElementById("name"); 
		if(account.value == null||account.value==""){
			$.MsgBox.Alert("提示","账号不能为空!");
			$("#account").focus();
		}else if(password.value == null||password.value==""){	
			$.MsgBox.Alert("提示","密码不能为空!");
			$("#password").focus();
		}else if(name.value == null||name.value==""){	
			$.MsgBox.Alert("提示","用户名称不能为空!");
			$("#name").focus();
		}else{
			$.MsgBox.Confirm("提示","确定添加?",function(){
				$.ajax({
			        type: "post",
			        dataType: "json",
			        url: '${ctx}/sysUser/addUser',
			        data:{
			        	account:$("#account").val(),
			        	password:$("#password").val(),
			        	name:$("#name").val(),
			        	phone:$("#phone").val(),
			        	type:$("#type").val(),
			        	status:$("#status").val()
			        },
			        success: function (data) {
			        	if(data.status=="1"){
			        		  $.MsgBox.Alert("提示",data.msg); 
				        	  $(".tab-main tr td input").val("");
				      		  $(".tab").eq(0).click();
					          query();
			        	}else{
			        		$.MsgBox.Alert("提示",data.msg);
							$("#account").focus();
			        	}
			        },
					error:function(){
						$.MsgBox.Alert("提示",data.msg);
						$("#account").focus();
					}
			    });
			});
		}
}

//新增用户信息重置
function resetAdminNamagerInfo(){
	
	$.MsgBox.Confirm("提示","确定重置信息!",function(){
		$(".tab-main tr td input").val("");
		$("#account").focus();
	});
}

/**
 * 点击修改按钮，界面跳转
 * 执行修改事件
 */

$("#btnEdit").on("click",function(){
	var result = $("#adminManagerTable").getSelections();
	if(parseInt(result.length)==0){
		$.MsgBox.Alert("提示","请选择一条记录!");
	}else if(parseInt(result.length)==1){
		$(".tab").eq(2).click();
		$("#u_id").val(result[0].id),
		$("#u_account").val(result[0].account),
    	$("#u_name").val(result[0].name),
    	$("#u_password").val(result[0].password),
    	$("#u_phone").val(result[0].phone),
    	$("#u_type").val(result[0].type),
    	$("#u_status").val(result[0].status)
		
	}else{
		$.MsgBox.Alert("提示","只能选择一条记录!");
	}
	
});

 function updateAdminNamagerManagerInfo(){
	var account = document.getElementById("u_account");
	var u_password = document.getElementById("u_password"); 
	var u_name = document.getElementById("u_name");
	if(u_account.value == null||u_account.value==""){
		$.MsgBox.Alert("提示","账号不能为空!");
		$("#u_account").focus();
	}else if(u_password.value == null||u_password.value==""){	
		$.MsgBox.Alert("提示","密码不能为空!");
		$("#u_password").focus();
	}else if(u_name.value == null||u_name.value==""){	
		$.MsgBox.Alert("提示","用户名称不能为空!");
		$("#u_name").focus();
	}
	if($("#u_id").val()==null || $("#u_id").val()==""){
		$.MsgBox.Alert("提示","请选择一条记录!");
		return ;
	}else{	
		$.MsgBox.Confirm("提示","确定修改用户信息？",function(){
			$.ajax({
		        type: "post",
		        dataType: "json",
		        url: '${ctx}/sysUser/updateUser',
		        data:{
		        	id:$("#u_id").val(),
		        	name:$("#u_name").val(),
		        	password:$("#u_password").val(),
		        	phone:$("#u_phone").val(),
		        	type:$("#u_type").val(),
		        	status:$("#u_status").val()
		        },
		        success: function (data) {
		        	if(data.status=="1"){
		        		$.MsgBox.Alert("提示",data.msg);
			        	query();
			        	$(".tab-main tr td input").val("");
			        	$(".tab").eq(0).click();
		        	}else{
		        		$.MsgBox.Alert("提示",data.msg);
		        		$("#account").focus();
		        	}
		        },
				error:function(){
					$.MsgBox.Alert("提示",data.msg);
				}
		    });
		});
	}
}


/**
 * 删除事件，可批量删除
 */
 $("#btnDel").on("click",function(){
 	var result = $("#adminManagerTable").getSelections();
 	var userIds = [];
 	for(var i=0; i<result.length; i++){
 		userIds.push(result[i].id);
 	}
 	if(parseInt(result.length)==0){
 		$.MsgBox.Alert("提示","请选择一条记录!"); 
 	}else{
 		$.MsgBox.Confirm("提示","确定删除用户信息？",function(){
 			$.ajax({
 	 	        type: "post",
 	 	        dataType: "json",
 	 	        url: '${ctx}/sysUser/deleteUsers',
 	 	        data:{
 	 	        	"userIds":userIds.join(",")
 	 	        },
 	 	        success: function (data) {
 	 	        	if(data.status=='1'){
 	 	        		$.MsgBox.Alert("提示",data.msg);
 	 	        		query();
 	 	        	}else{
 	 	        		$.MsgBox.Alert("提示",data.msg);
 	 	        	}
 	 	        },
 	 			error:function(){
 	 				$.MsgBox.Alert("提示",data.msg);
 	 			}
 	 	    });
 		});
 	}
 	
 });
 

 $("#advancedSearchbtnAdmin").on("click",function(){
		 if($("#advancedSearchAdmin").css('display')=="block"){
		    $("#advancedSearchAdminText").html('高级搜索');
			$("#advancedSearchAdminSpan").removeClass('glyphicon glyphicon-chevron-up');
			$("#advancedSearchAdminSpan").addClass('glyphicon glyphicon-chevron-down');
			$("#advancedSearchAdmin").css("display","none");
			$("#searchType").val('');
        	$("#searchStatus").val('');
		 }else{
		    $("#advancedSearchAdminText").html('收起条件');
			$("#advancedSearchAdminSpan").removeClass('glyphicon glyphicon-chevron-down');
			$("#advancedSearchAdminSpan").addClass('glyphicon glyphicon-chevron-up');
			$("#advancedSearchAdmin").css("display","block");
		 }
	});
 
 
 $("#btnSearchAdmin").click(function(){
		query();
	});


</script>
</html>